<template>
  <div class="partyorgan">
    <title-middle title="党组织所属单位"></title-middle>
    <div class="top">
      <span class="label">{{ total.label }}:</span>
      <span class="value">{{ total.value }}</span>
      <span class="label">个</span>
    </div>
    <div class="bottom">
      <div class="barEchart" ref="barEchart"></div>
      <div class="legendContainer">
        <div class="legend" v-for="(item, index) in dataList" :key="index">
          <i class="icon"></i>
          <div class="content">
            <div class="blabel">{{ item.label }}</div>
            <div class="bvalue">
              {{ item.value }}
              <span class="unit">人</span>
            </div>
          </div>
          <div class="rate">
            {{ item.rate }}
            <span class="unit">%</span>
          </div>
        </div>
      </div>
      <div class="blueBorder"></div>
      <div class="redBorder"></div>
    </div>
  </div>
</template>
<script setup>
import { ref, inject, onMounted } from 'vue'
const echarts = inject('echarts')
let barEchart = ref(null)
let myEchart = null
let total = ref({ label: '总计单位', value: 100 })
let dataList = ref([
  { label: '本市', value: 127, rate: 78.4 },
  { label: '非本市', value: 35, rate: 21.6 }
])
let colorList = [
  ['#FF7C5E', '#FF3663'],
  ['#5EC4FF', '#218AF5']
]
let data = {
  xdata: ['本市', '非本市'],
  ydata: [127, 35]
}
onMounted(() => {
  setEchart()
})
const setEchart = () => {
  if (myEchart != null && myEchart != '' && myEchart != undefined) {
    myEchart.dispose() //销毁
  }
  myEchart = echarts.init(barEchart.value, null, { renderer: 'svg' })
  let option = {
    tooltip: {
      trigger: 'axis',
      textStyle: {
        fontSize: 22 // 字体大小
      },
      axisPointer: {
        // Use axis to trigger tooltip
        type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
      }
    },
    grid: {
      left: '0%',
      right: '5%',
      bottom: '0%',
      top: '10%',
      containLabel: true
    },
    xAxis: {
      type: 'value',
      max: 127,
      axisTick: {
        show: false
      },
      axisLine: {
        show: false
      },
      splitLine: {
        //修改背景线条样式
        show: false
      },
      axisLabel: {
        show: false
      }
    },
    yAxis: {
      type: 'category',
      data: data.xdata.reverse(),
      axisTick: {
        show: false
      },
      axisLine: {
        show: false
      },
      axisLabel: {
        show: false
      },
      splitLine: {
        //修改背景线条样式
        show: false
      }
    },
    series: [
      {
        type: 'bar',
        barWidth: 20,
        emphasis: {
          focus: 'series'
        },
        data: data.ydata.reverse(),
        itemStyle: {
          color: (param) => {
            return new echarts.graphic.LinearGradient(0, 0, 1, 0, [
              { offset: 0, color: colorList[param.dataIndex][0] },
              { offset: 1, color: colorList[param.dataIndex][1] }
            ])
          }
        }
      }
    ]
  }
  myEchart.setOption(option)
}
</script>
<style scoped lang="scss">
.partyorgan {
  .top {
    width: 260px;
    height: 59px;
    box-sizing: border-box;
    background: url('@/assets/images/thirdpage/labelBg.png') no-repeat;
    background-size: 100% 100%;
    padding-left: 25px;
    margin-top: 20px;
    .label {
      font-size: 21px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      font-style: italic;
      color: #ffffff;
    }
    .value {
      font-size: 30px;
      font-family: Microsoft YaHei;
      font-weight: bold;
      font-style: italic;
      color: #f9c318;
      margin: 0 10px;
    }
  }
  .bottom {
    position: relative;
    .legendContainer {
      position: absolute;
      top: 29px;
      left: 0;
      z-index: -1;
      .legend {
        display: flex;
        justify-content: space-between;
        .icon {
          display: inline-block;
          width: 47.5px;
          height: 47.5px;
          box-sizing: border-box;
          background: url('@/assets/images/thirdpage/blueCity.png') no-repeat;
          background-size: 100% 100%;
        }
        .content {
          transform: translate(10px, -15px);
          .blabel {
            font-size: 21px;
            font-family: Microsoft YaHei;
            font-weight: 400;
            font-style: italic;
            color: #ffffff;
          }
          .bvalue {
            font-size: 33px;
            font-family: Microsoft YaHei;
            font-weight: bold;
            font-style: italic;
            color: #18dcf9;
            .unit {
              font-size: 19px;
              font-family: Microsoft YaHei;
              font-weight: 400;
              font-style: italic;
              color: #ffffff;
            }
          }
        }
        .rate {
          font-size: 34px;
          font-family: Microsoft YaHei;
          font-weight: bold;
          font-style: italic;
          color: #18dcf9;
          transform: translate(100px, 10px);
          .unit {
            font-size: 19px;
            font-family: Microsoft YaHei;
            font-weight: 400;
            font-style: italic;
            color: #ffffff;
          }
        }
        &:nth-child(2) {
          margin-top: 70px;
          .icon {
            background: url('@/assets/images/thirdpage/redCity.png') no-repeat;
            background-size: 100% 100%;
          }
          .bvalue {
            color: #ff3663;
          }
          .rate {
            color: #ff3663;
          }
        }
      }
    }

    .barEchart {
      width: 350px;
      height: 310px;
      //   background-color: red;
    }
    .blueBorder,
    .redBorder {
      position: absolute;
      top: 90px;
      left: 0;
      width: 333px;
      height: 20px;
      border: 1px solid #2dc1ff;
    }
    .redBorder {
      top: 229px;
      left: 0;
      border: 1px solid #ff3863;
    }
  }
}
</style>
